<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数组的定义</title>

    <script type="text/javascript">
<!--        数组定义-->
        // 方式1,
        var cars1=["Audi","BMW","Volvo"];
        console.log("cars1= "+cars1);
        console.log(cars1[1]);

        // 方式2,
        var cars2 =[]; //空数组.
        // 添加元素.
        cars2[0] = "奥迪";
        cars2[1] = "宝马";
        cars2[2] ="奔驰";
        console.log("cars2 = "+cars2);
        console.log("cars2[2]= "+cars2[2]);
        console.log("cars2[10]= "+cars2[10]); // 元素不存在返回 undefined。

//  数组定义方式3.
        var cars3 = new Array("Audi","BMW","Volvo");
        console.log("cars3 = "+cars3);
        console.log("cars3[0] = "+cars3[0]);
        //数组定义方式4.
        var cars4 = new Array();//空数组.
        console.log(typeof cars4);
        cars4[0] = "法拉利";
        cars4[1] = "保时捷";
        cars4[2] = "yy";
        cars4[0] = "zz";
        cars4[8] = "红旗";// 4. || 或运算, 有两种情况 => 老韩解读(即|| 返回值是遵守短路或的机制)
        console.log("cars4[3] = "+cars4[3]);
        console.log("cars4[4] = "+cars4);
    </script>
</head>
<body>

</body>
</html>